package inits

import (
	"app-webapi/comm/g"
	"fmt"
	// app-webapi 项目名称
	nested "github.com/antonfisher/nested-logrus-formatter"
	"github.com/sirupsen/logrus"
	"runtime"
)

func InitLogger() {

	logger := logrus.New()
	logger.SetLevel(4) //INFO 4
	logger.SetReportCaller(true)
	logger.SetFormatter(&nested.Formatter{
		CallerFirst: true,

		CustomCallerFormatter: func(frame *runtime.Frame) string {

			//取文件名末尾
			file := frame.File
			short := file
			for i := len(file) - 1; i > 0; i-- {
				if file[i] == '/' {
					short = file[i+1:]
					break
				}
			}
			file = short
			return fmt.Sprintf(" %10s:%-4d", short, frame.Line)
		},
		TimestampFormat: "2006/01/02 15:04:05",
		FieldsOrder:     []string{"component", "category"},
	})

	g.Logger = logger
}
